 /*
 * @name: 员工激励设置
 * @Author: along
 * @Date: 2019-07-13
 * @Last Modified by: along
 * @Last Modified time: 2020-07-14
 */
<template>
    <div class="container companyStaffSeting">
        <div class="companyStaffSeting-head">
            <p class="companyStaffSeting-head-title">
                员工激励设置
            </p>
            <div class="companyStaffSeting-head-wrap">
                <el-button
                    size="small"
                    type="primary"
                    :disabled="!authResult.auth_system"
                    @click="()=>{
                        this.$router.push({
                            name: 'companySystemStaff'
                        })
                    }"
                >
                    管理员工
                </el-button>
                <el-button
                    size="small"
                    type="primary"
                    style="height:32px;margin-left:24px;"
                    :disabled="!authResult.auth_add"
                    @click="fnOpenUser()"
                >
                    提交已拓展精英
                </el-button>
                <el-button
                    size="small"
                    type="primary"
                    style="height:32px;margin-left:24px;"
                    @click="dialog.dialogUpload = true"
                    :disabled="!authResult.add_submit"
                >
                    批量提交
                </el-button>
            </div>
        </div>
        <!-- header -->
        <div class="header-nav">
            <div class="header-left">
                <div class="header-new-box">
                    <p class="header-new-box-title">搜索精英:</p>
                    <el-input
                        v-model="head.keyword"
                        placeholder="可搜索精英邀请码、手机号、姓名"
                        size="small"
                        clearable
                        suffix-icon="el-icon-search"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                        style="width:250px"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">所在学校:</p>
                    <el-cascader
                        placeholder="请选择"
                        :options="provideList"
                        filterable
                        clearable
                        change-on-select
                        expand-trigger="click"
                        v-model="head.school"
                        @change="getTableData(1)"
                        size="small"
                        :props="{
                            label: 'name',
                            value: 'id',
                            children: 'children'
                        }"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">提交时间:</p>
                    <el-date-picker
                        v-model="head.date"
                        size="small"
                        type="datetimerange"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        @change="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">上级为员工:</p>
                    <el-select
                        v-model="head.staff"
                        clearable
                        filterable
                        placeholder="请选择"
                        size="small"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in staffList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>
            </div>
        </div>
        <!-- /header -->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            border
            ref="companyStaffSeting"
            class="tableData"
            @sort-change="handleSortChanged"
            @select="fnSelect"
            @select-all="fnSelectAllTop"
            @selection-change="handleSelectionChange"
        >
            <el-table-column
                type="selection"
                width="40"
                fixed="left"
                :selectable="selectable"
            />
            <el-table-column
                type="index"
                width="80"
                label="序号"
                align="left"
            />
            <el-table-column
                prop="true_name"
                label="精英姓名"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            />
            <el-table-column
                prop="phone"
                label="精英手机号"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                :width="140"
            />
            <el-table-column
                prop="school"
                label="所在学校"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            />
            <el-table-column
                prop="invite_code"
                label="邀请码"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            />
            <el-table-column
                prop="parent_stuagent_employee"
                label="上级是否为员工"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                :width="140"
            >
                <template slot-scope="scope">
                    <p v-if="scope.row.parent_stuagent_employee.status == 1">
                        是 {{ '-' + scope.row.parent_stuagent_employee.true_name }}
                    </p>
                    <p v-if="scope.row.parent_stuagent_employee.status == 0">
                        否
                    </p>
                </template>
            </el-table-column>
            <el-table-column
                prop="position1"
                label="精英拓展岗"
                align="left"
                :width="120"
            >
                <template slot-scope="scope">
                    <div
                        class="sort-wrap"
                    >
                        {{ scope.row.position1.true_name ? scope.row.position1.true_name : '--' }}
                        <span class="sort-spliter" />
                        <el-button
                            type="text"
                            class="btn-sort"
                            @click="fnEditStaff(scope.row, 1)"
                        >
                            <i class="el-icon-edit" />
                        </el-button>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                prop="position2"
                label="精英运营岗"
                align="left"
                :width="120"
            >
                <template slot-scope="scope">
                    <div
                        class="sort-wrap"
                    >
                        {{ scope.row.position2.true_name ? scope.row.position2.true_name : '--' }}
                        <span class="sort-spliter" />
                        <el-button
                            type="text"
                            class="btn-sort"
                            @click="fnEditStaff(scope.row, 2)"
                        >
                            <i class="el-icon-edit" />
                        </el-button>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                prop="position3"
                label="私域运营岗-活动"
                align="left"
                :width="140"
            >
                <template slot-scope="scope">
                    <div
                        class="sort-wrap"
                    >
                        {{ scope.row.position3.true_name ? scope.row.position3.true_name : '--' }}
                        <span class="sort-spliter" />
                        <el-button
                            type="text"
                            class="btn-sort"
                            @click="fnEditStaff(scope.row, 3)"
                        >
                            <i class="el-icon-edit" />
                        </el-button>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                prop="position4"
                label="私域运营岗-交易"
                align="left"
                :width="140"
            >
                <template slot-scope="scope">
                    <div
                        class="sort-wrap"
                    >
                        {{ scope.row.position4.true_name ? scope.row.position4.true_name : '--' }}
                        <span class="sort-spliter" />
                        <el-button
                            type="text"
                            class="btn-sort"
                            @click="fnEditStaff(scope.row, 4)"
                        >
                            <i class="el-icon-edit" />
                        </el-button>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                prop="link_time"
                label="提交时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                sortable
                :width="140"
            >
                <template slot-scope="scope">
                    {{ scope.row.link_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                </template>
            </el-table-column>
            <el-table-column
                label="操作"
                align="left"
                fixed="right"
            >
                <template slot-scope="scope">
                    <el-button
                        type="text"
                        class="curse-add"
                        style="padding: 0px"
                        @click="fnRemoveData(scope.row)"
                    >
                        删除
                    </el-button>
                    <el-button
                        type="text"
                        class="curse-add"
                        :disabled="scope.row.parent_stuagent_employee.status == 0"
                        style="padding: 0px;margin-left:0"
                        @click="fnChangeSuper(scope.row)"
                    >
                        更换上级
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- /table -->

        <!-- /分页 -->
        <div class="pagination-wrapper clearfix">
            <el-checkbox
                v-model="checkedAll"
                :indeterminate="checkIndeterminate"
                @change="fnChangeChecked"
            >全选</el-checkbox>
            <el-button
                type="text"
                @click="fnChangeSuper(false)"
                :disabled="multipleSelection.length == 0 ? true : false"
                style="margin-left:20px"
            >更换上级</el-button>
            <el-pagination
                background
                layout="total, prev, pager, next"
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </div>

        <!-- 更换已绑定员工 -->
        <el-dialog
            title="更换已绑定员工"
            :visible.sync="dialog.dialogStaff"
            width="640px"
            :close-on-click-modal="false"
            class="staff"
        >
            <span class="staff-title">
                请选择要更换的员工
            </span>
            <div class="staff-wrap">
                <el-radio-group v-model="dialog.staff">
                    <el-radio
                        v-for="(item,index) in dialog.staffList"
                        :key="index"
                        :label="item.student_no"
                        class="staff-radio"
                        @change="dialog.staffName = item.true_name"
                    >
                        {{ item.true_name }}
                    </el-radio>
                </el-radio-group>
                <p
                    v-if="dialog.staffName"
                    class="staff-wrap-name"
                >
                    当前选定: {{ dialog.staffName }}
                </p>
            </div>
            <span
                slot="footer"
                class="dialog-footer">
                <el-button
                    @click="dialog.dialogStaff = false"
                    size="small"
                    :style="{width: '126px', height: '36px'}"
                >
                    取 消
                </el-button>
                <el-button
                    type="primary"
                    size="small"
                    :style="{width: '126px', height: '36px', marginLeft: '52px'}"
                    @click="fnSaveStaff()"
                >
                    保 存
                </el-button>
            </span>
        </el-dialog>

        <!-- 选择精英用户 -->
        <el-dialog
            title="选择精英用户"
            :visible.sync="dialog.dialogVisibleBind"
            width="580px"
            :close-on-click-modal="false"
            class="staff zd-select-user"
        >
            <el-form
                :model="ruleFormBind"
                label-width="100px"
                class="demo-ruleForm"
                @submit.native.prevent
            >
                <div class="zd-user-search">
                    <el-form-item
                        label="精英用户"
                        class="user-title"
                    >
                        <el-input
                            v-model="ruleFormBind.phone"
                            size="small"
                            @keyup.native.enter="fnBindSearch()"
                            placeholder="手机号或用户ID"
                            :style="{'width': '300px'}"
                        />
                        <el-button
                            type="primary"
                            size="small"
                            @click="fnBindSearch()"
                            :style="{width: '76px', height: '32px', position: 'relative', zIndex: '99', left: '-10px'}"
                        >
                            搜索
                        </el-button>
                    </el-form-item>
                </div>
                <el-table
                    :data="tableDataBind"
                    height="100%"
                    style="width: 100%;max-height:500px"
                    border
                    v-if="tableDataBind.length > 0"
                >
                    <el-table-column
                        label="用户姓名"
                        prop="true_name"
                        show-overflow-tooltip
                        :formatter="emptyFormatter"
                        align="center"
                    />
                    <el-table-column
                        label="电话号码"
                        prop="phone"
                        show-overflow-tooltip
                        :formatter="emptyFormatter"
                        align="center"
                    />
                    <el-table-column
                        label="学校名称"
                        prop="school"
                        show-overflow-tooltip
                        :formatter="emptyFormatter"
                        align="center"
                    />
                    <el-table-column
                        label="操作"
                        prop="school_name"
                        show-overflow-tooltip
                        :formatter="emptyFormatter"
                        align="center"
                    >
                        <template slot-scope="scope">
                            <span
                                @click="fnDeleteData(scope.$index)"
                                class="el-delData"
                                style="color: #1890FF;cursor: pointer"
                            >
                                删除
                            </span>
                        </template>
                    </el-table-column>
                </el-table>
            </el-form>
            <span
                slot="footer"
                class="dialog-footer"
            >
                <el-button
                    @click="dialog.dialogVisibleBind = false"
                    size="small"
                    :style="{width: '126px', height: '36px'}"
                >
                    返回列表
                </el-button>
                <el-button
                    type="primary"
                    size="small"
                    :style="{width: '126px', height: '36px', marginLeft: '52px'}"
                    @click="fnConirmBind()"
                >
                    选择
                </el-button>
            </span>
        </el-dialog>

        <!-- 提交已扩展精英 -->
        <el-dialog
            title="提交已拓展精英"
            :visible.sync="dialog.dialogUser"
            width="640px"
            :close-on-click-modal="false"
            class="staff zd-dialogUser"
        >
            <div class="user">
                <el-form
                    :model="ruleForm"
                    :rules="rules"
                    ref="ruleForm"
                    label-width="100px"
                    class="demo-ruleForm"
                    :label-position="'right'"
                >
                    <el-form-item
                        label="选择精英"
                        prop="true_name"
                    >
                        <div @click="fnChangeUser()">
                            <div
                                class="user-wrap"
                                v-if="!ruleForm.true_name"
                            >
                                <i class="iconfont el-icon-hand-iconjia"/>
                                选择精英用户
                            </div>
                            <div
                                v-if="ruleForm.true_name"
                                class="user-info"
                            >
                                {{ ruleForm.true_name + '-' + ruleForm.phone }}
                            </div>
                        </div>
                    </el-form-item>
                    <el-form-item
                        label="所属精英拓展"
                    >
                        <!-- prop="elite_development" -->
                        <el-select
                            v-model="ruleForm.elite_development"
                            clearable
                            filterable
                            placeholder="请选择"
                            size="small"
                            :style="{width: '424px', height: '32px'}"
                        >
                            <el-option
                                v-for="item in ruleForm.developmentList"
                                :key="item.student_no"
                                :label="item.true_name"
                                :value="item.student_no"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item
                        label="所属精英运营"
                    >
                        <!-- prop="elite_operation" -->
                        <el-select
                            v-model="ruleForm.elite_operation"
                            clearable
                            filterable
                            placeholder="请选择"
                            size="small"
                            :style="{width: '424px', height: '32px'}"
                        >
                            <el-option
                                v-for="item in ruleForm.oprationList"
                                :key="item.student_no"
                                :label="item.true_name"
                                :value="item.student_no"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item
                        label="私域运营活动"
                    >
                        <!-- prop="private_domain_operation" -->
                        <el-select
                            v-model="ruleForm.private_domain_operation"
                            clearable
                            filterable
                            placeholder="请选择"
                            size="small"
                            :style="{width: '424px', height: '32px'}"
                        >
                            <el-option
                                v-for="item in ruleForm.privateList"
                                :key="item.student_no"
                                :label="item.true_name"
                                :value="item.student_no"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item
                        label="私域运营交易"
                    >
                        <!-- prop="private_domain_operation_money" -->
                        <el-select
                            v-model="ruleForm.private_domain_operation_money"
                            clearable
                            filterable
                            placeholder="请选择"
                            size="small"
                            :style="{width: '424px', height: '32px'}"
                        >
                            <el-option
                                v-for="item in ruleForm.privateListMoney"
                                :key="item.student_no"
                                :label="item.true_name"
                                :value="item.student_no"
                            />
                        </el-select>
                    </el-form-item>
                </el-form>
            </div>
            <span
                slot="footer"
                class="dialog-footer"
                style="margin-top: 10px;margin-bottom:22px"
            >
                <el-button
                    @click="dialog.dialogUser = false"
                    size="small"
                    :style="{width: '126px', height: '36px'}"
                >
                    返回列表
                </el-button>
                <el-button
                    type="primary"
                    size="small"
                    :style="{width: '126px', height: '36px', marginLeft: '52px'}"
                    @click="fnSubmitData('ruleForm')"
                >
                    提 交
                </el-button>
            </span>
        </el-dialog>

        <!-- 批量上传 -->
        <el-dialog
            title="提交已拓展精英"
            :visible.sync="dialog.dialogUpload"
            width="640px"
            :close-on-click-modal="false"
            class="staff zd-upload"
        >
            <div class="upload">
                <input
                    class="import-input"
                    accept=".csv"
                    type="file"
                    @change="fnExportStudent($event)"
                >
                <div
                    class="upload-wrap"
                    v-if="!name"
                >
                    <i class="el-icon-upload2" />
                    上传已拓展的精英表格
                </div>
                <div
                    class="upload-wrap-success"
                    v-if="name"
                >
                    <span class="upload-wrap-success-text">
                        {{ name }}
                    </span>
                    <i class="el-icon-upload2" />
                </div>
            </div>
            <div class="upload">
                <div class="upload-main">
                    <p class="upload-main-text">
                        支持扩展名：.csv
                    </p>
                    <p
                        class="upload-down"
                        @click="fnDown()"
                    >
                        下载模版
                    </p>
                </div>
            </div>
            <span
                slot="footer"
                class="dialog-footer"
                style="margin-top: 10px"
            >
                <el-button
                    @click="dialog.dialogUpload = false"
                    size="small"
                    :style="{width: '126px', height: '36px'}"
                >
                    取 消
                </el-button>
                <el-button
                    type="primary"
                    size="small"
                    :style="{width: '126px', height: '36px', marginLeft: '52px'}"
                    @click="fnUplaoFile()"
                >
                    提 交
                </el-button>
            </span>
        </el-dialog>

        <!-- 提交失败 -->
        <el-dialog
            title="提交失败"
            :visible.sync="dialog.dialogError"
            width="640px"
            :close-on-click-modal="false"
            class="staff error"
        >
            <p class="error-title">
                以下信息提交失败，请核对后重新提交
            </p>
            <el-table
                :data="tableDataError"
                height="100%"
                style="width: 100%;max-height:500px"
                border
                v-if="tableDataError.length > 0"
            >
                <el-table-column
                    label="第几行"
                    prop="line"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                >
                    <template slot-scope="scope">
                        第{{ scope.row.line }}行
                    </template>
                </el-table-column>
                <el-table-column
                    label="手机号"
                    prop="phone"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                />
                <el-table-column
                    label="失败原因"
                    prop="reason"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                />
            </el-table>
            <span
                slot="footer"
                class="dialog-footer"
                style="margin-top: 10px"
            >
                <el-button
                    @click="dialog.dialogError = false"
                    size="small"
                    :style="{width: '126px', height: '36px'}"
                >
                    知道了
                </el-button>
            </span>
        </el-dialog>

        <!-- 图片预览 -->
        <img-preview ref="preview" />
    </div>
</template>

<script>
import imgPreview from '@/components/common/img-preview';
import {getDate} from '@/assets/js/utils';
import { back } from '@/mixin/back';
export default {
    mixins: [back],
    components: {
        imgPreview
    },
    data () {
        return {
            name: '',
            file: '',
            tableDataError: [],
            staff: {
                type: '',
                agent_no: ''
            },
            provideList: [],
            type: '', //0:单独更换上级 1:批量更换上级 2:提交已拓展员工
            ruleForm: {
                true_name: '',
                phone: '',
                student_no: '',
                agent_no: '',
                elite_development: '',
                elite_operation: '',
                private_domain_operation: '',
                private_domain_operation_money: '',
                developmentList: [],
                oprationList: [],
                privateList: [],
                privateListMoney: []
            },
            rules: {
                true_name: [
                    { required: true, message: '请选择精英', trigger: 'change' }
                ],
                elite_development: [
                    { required: true, message: '请选择精英拓展', trigger: 'change' }
                ],
                elite_operation: [
                    { required: true, message: '请选择精英运营', trigger: 'change' }
                ],
                private_domain_operation: [
                    { required: true, message: '请选择私域运营-活动', trigger: 'change' }
                ],
                private_domain_operation_money: [
                    { required: true, message: '请选择私域运营-交易', trigger: 'change' }
                ]
            },
            tableDataBind: [],
            ruleFormBind: {
                phone: ''
            },
            dialog: {
                dialogStaff: false,
                staffId: '',
                staffName: '',
                staffList: [],
                dialogVisibleBind: false,
                dialogUser: false,
                dialogUpload: false,
                dialogError: false
            },
            checkIndeterminate: false,
            multipleSelection: [],
            checkedAll: false,
            head: {
                keyword: '',
                school: '',
                date: '',
                staff: 99
            },
            staffList: [{
                value: 99,
                label: '全部'
            },{
                value: 1,
                label: '是'
            },{
                value: 0,
                label: '否'
            }],
            filterData: {
                sort_field: 0,
                sort_type: 1
            },
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
            tableData: [],
            authResult: {}
        };
    },
    filters: {},
    computed: {},
    watch: {
        dialog: {
            handler: function (val, oldVal) {
                if(!val.dialogUser) {
                    this.ruleForm = {
                        true_name: '',
                        phone: '',
                        student_no: '',
                        agent_no: '',
                        elite_development: '',
                        elite_operation: '',
                        private_domain_operation: '',
                        developmentList: [],
                        oprationList: [],
                        privateList: []
                    };
                }
                if(!val.dialogVisibleBind) {
                    this.tableDataBind = [];
                }
                if(!val.dialogUpload) {
                    this.file = '';
                    this.name = '';
                }
            },
            deep: true,
        }
    },
    mounted () {
        this.$store.commit('SET_HEADER', [{ title: "APP后台"},{title: '掌大精英'},{title: '员工激励设置'}]);
        this.authResult = this.$route.meta.authResult;
        this.getTableData();
        this.getSchoolTree();
    },
    methods: {
        /**
         * 获取表格数据
         */
        getTableData (page) {
            this.$post('/student/stuagent_employee_link%5Cget_list', {
                page_id: page || this.page.now_page,
                keyword: this.head.keyword,
                school_id: this.head.school.length > 0 ? this.head.school[2] : '',
                link_start_time: this.head.date === null || this.head.date == '' ? '' : getDate(new Date(this.head.date[0])),
                link_end_time: this.head.date === null || this.head.date == '' ? '' : (getDate(new Date(this.head.date[1])) + 86400),
                parent_is_employee: this.head.staff,
                sort_field: this.filterData.sort_field,
                sort_type: this.filterData.sort_type
            }, resp => {
                if (resp.code == 1) {
                    this.tableData = resp.data.list;
                    this.page.now_page = resp.data.page.now_page;
                    this.page.total_count = resp.data.page.total_count;
                    this.page.page_size = resp.data.page.page_size;
                }
            });
        },

        /**
         * 获取省+市+学校三级联动数据
         */
        getSchoolTree () {
            this.$post('/student/local_info%5Cschool_tree', {},resp=>{
                if (resp.code == 1) {
                    this.provideList = resp.data.tree;
                } else if (resp.code == 0) {
                    this.$message({
                        type: 'waring',
                        message: resp.msg
                    });
                }
            });
        },

        /**
        *   打开更换员工弹窗
        */
        fnEditStaff (row, type) {
            this.staff.type = type;
            this.staff.agent_no = row.agent_no;
            this.getBindList(type);
            if(type == 1) {
                this.dialog.staff = row.position1.student_no;
            } else if(type == 2) {
                this.dialog.staff = row.position2.student_no;
            } else if (type == 3) {
                this.dialog.staff = row.position3.student_no;
            } else if (type == 4) {
                this.dialog.staff = row.position4.student_no;
            }
            this.dialog.staffName = this.dialog.staffId = '';
            this.dialog.dialogStaff = !this.dialog.dialogStaff;
        },

        getBindList (type) {
            this.$post('/student/stuagent_employee%5Cget_list', {
                position: type
            }, resp => {
                if (resp.code == 1) {
                    this.dialog.staffList = resp.data.list;
                }
            });
        },

        /**
         * 保存更改员工
         */
        fnSaveStaff () {
            if(this.dialog.staffName) {
                this.$post('/student/stuagent_employee_link%5Cbind',{
                    agent_no: this.staff.agent_no,
                    position: this.staff.type,
                    student_no: this.dialog.staff
                },resp=>{
                    if (resp.code == 1) {
                        this.getTableData();
                        this.dialog.dialogStaff = !this.dialog.dialogStaff;
                        this.$notify({
                            title: '提示',
                            message: '更换成功',
                            type: 'success'
                        });
                    } else if (resp.code == 0) {
                        this.$notify({
                            title: '警告',
                            message: resp.msg,
                            type: 'warning',
                            duration: 2000
                        });
                    }
                });
            } else {
                this.$notify({
                    title: '警告',
                    message: '请先选择要更换的员工',
                    type: 'warning',
                    duration: 2000
                });
            }
        },

        /**
        *   更换上级
        *   @param      {Number}        type    //0:单独 1:批量
         */
        fnChangeSuper (row) {
            this.type = row ? 0 : 1;
            this.staff.agent_no = row ? row.student_no : '';
            this.dialog.dialogVisibleBind = !this.dialog.dialogVisibleBind;
        },

        /**
         * 删除
         */
        fnRemoveData (row) {
            this.$confirm('是否确认删除?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$post('/student/stuagent_employee_link%5Cdelete',{
                    agent_no: row.agent_no
                },resp=>{
                    if (resp.code == 1) {
                        this.getTableData();
                        this.$notify({
                            title: '提示',
                            message: '删除成功',
                            type: 'success',
                            duration: 2000
                        });
                    } else if (resp.code == 0) {
                        this.$notify({
                            title: '警告',
                            message: resp.msg,
                            type: 'warning',
                            duration: 2000
                        });
                    }
                });
            });
        },

        /**
         * 搜索
         */
        fnBindSearch () {
            if(this.ruleFormBind.phone == '') {
                this.$notify({
                    title: '警告',
                    message: '请输入手机号或用户ID',
                    type: 'warning',
                    duration: 2000
                });
                return;
            }

            this.$post('/student/stuagent%5Cget_student_simple_list',{
                keyword_student_id: this.ruleFormBind.phone
            },resp=>{
                if (resp.code == 1) {
                    if (resp.data.list.length == 0) {
                        this.$notify({
                            title: '警告',
                            message: '未搜索到该用户',
                            type: 'warning',
                            duration: 2000
                        });
                        this.ruleFormBind.phone = '';
                        return;
                    }
                    this.tableDataBind = resp.data.list;
                    this.ruleFormBind.phone = '';
                } else if (resp.code == 0) {
                    this.$notify({
                        title: '警告',
                        message: resp.msg,
                        type: 'warning',
                        duration: 2000
                    });
                }
            });
        },

        /**
         * 删除用户
         */
        fnDeleteData (index) {
            this.tableDataBind.splice(index,1);
        },

        /**
         * 确认绑定客服
         */
        fnConirmBind () {
            if (this.tableDataBind.length == 0) {
                this.$notify({
                    title: '警告',
                    message: '请输入手机号或用户ID',
                    type: 'warning',
                    duration: 2000
                });
                return;
            }

            let kf_student = [];

            this.tableDataBind.map(item=>{
                kf_student.push(item.student_no);
            });

            if(this.type === 0) {//单独
                this.$post('/student/stuagent%5Cchange_agent',{
                    new_agent_no: this.tableDataBind[0].agent_no,
                    student_no: this.staff.agent_no
                },resp=>{
                    if (resp.code == 1) {
                        this.getTableData();
                        this.dialog.dialogVisibleBind = !this.dialog.dialogVisibleBind;
                        this.$notify({
                            title: '提示',
                            message: '设置成功',
                            type: 'success',
                            duration: 2000
                        });
                    } else if (resp.code == 0) {
                        this.$notify({
                            title: '警告',
                            message: resp.msg,
                            type: 'warning',
                            duration: 2000
                        });
                    }
                });
            } else if (this.type === 1) {//批量
                console.log(this.multipleSelection, 'multipleSelection');

                this.multipleSelection.forEach(option => {
                    if(option.parent_stuagent_employee.status) {
                        this.$post('/student/stuagent%5Cchange_agent',{
                            new_agent_no: option.agent_no,
                            student_no: kf_student.join()
                        },resp=>{
                            if (resp.code == 1) {
                                //
                            }
                        });
                    }
                });

                setTimeout(()=>{
                    this.getTableData();
                    this.dialog.dialogVisibleBind = !this.dialog.dialogVisibleBind;
                    this.$notify({
                        title: '提示',
                        message: '设置成功',
                        type: 'success',
                        duration: 2000
                    });
                },500);

            } else if (this.type === 2) {//提交已拓展精英
                console.log(this.tableDataBind, 'data');
                if(this.tableDataBind.length == 1) {
                    this.$set(this.ruleForm, 'true_name', this.tableDataBind[0].true_name);
                    this.$set(this.ruleForm, 'phone', this.tableDataBind[0].phone);
                    this.$set(this.ruleForm, 'student_no', this.tableDataBind[0].student_no);
                    this.$set(this.ruleForm, 'agent_no', this.tableDataBind[0].agent_no);
                    this.dialog.dialogVisibleBind = !this.dialog.dialogVisibleBind;
                } else {
                    this.$notify({
                        title: '警告',
                        message: '最多只可选择一个',
                        type: 'warning',
                        duration: 2000
                    });
                }
            }
        },

        /**
         * 选择精英用户
         */
        fnChangeUser () {
            this.type = 2;
            this.dialog.dialogVisibleBind = !this.dialog.dialogVisibleBind;
        },

        /**
         * 提交已拓展精英
         */
        fnSubmitData (formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    console.log(this.ruleForm, 'ruleForm');
                    this.$post('/student/stuagent_employee_link%5Cadd',{
                        agent_no: this.ruleForm.agent_no,
                        position1_student_no: this.ruleForm.elite_development,
                        position2_student_no: this.ruleForm.elite_operation,
                        position3_student_no: this.ruleForm.private_domain_operation,
                        position4_student_no: this.ruleForm.private_domain_operation_money
                    },resp=>{
                        if (resp.code == 1) {
                            this.getTableData();
                            this.$notify({
                                title: '提示',
                                message: '提交成功',
                                type: 'success',
                                duration: 2000
                            });
                            this.dialog.dialogUser = !this.dialog.dialogUser;
                        } else if (resp.code == 0) {
                            this.$notify({
                                title: '警告',
                                message: resp.msg,
                                type: 'warning',
                                duration: 2000
                            });
                        }
                    });
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },

        /**
         * 提交已拓展精英
         */
        fnOpenUser () {
            this.dialog.dialogUser = !this.dialog.dialogUser;
            this.initUser();
        },

        /**
         * 初始化精英数据
         *      所属精英拓展/所属精英运营/所属私域运营
         */
        initUser () {
            this.getSimpleList(1, resp => {
                this.$set(this.ruleForm, 'developmentList', resp);
            });
            this.getSimpleList(2, resp => {
                this.$set(this.ruleForm, 'oprationList', resp);
            });
            this.getSimpleList(3, resp => {
                this.$set(this.ruleForm, 'privateList', resp);
            });
            this.getSimpleList(4, resp => {
                this.$set(this.ruleForm, 'privateListMoney', resp);
            });
        },

        getSimpleList (type, callback) {
            return new Promise((resolve, reject) => {
                this.$post('/student/stuagent_employee%5Cget_simple_list',{
                    position: type
                },resp=>{
                    if (resp.code == 1) {
                        if(resp.data.list) {
                            callback(resp.data.list);
                        }
                    } else if (resp.code == 0) {
                        this.$notify({
                            title: '警告',
                            message: resp.msg,
                            type: 'warning',
                            duration: 2000
                        });
                    }
                });
            });
        },

        /**
         * 下载模版
         */
        fnDown () {
            let base = this.$baseUrl;
            let ticket = localStorage.getItem('sessionTicket');
            let url = `${base}/student/stuagent_employee_link%5Cget_import_template?&__ticket=${ticket}`;

            window.open(url);
        },

        /**
         * 获取表格信息
         */
        fnExportStudent (event) {
            let file = event.target.files[0];

            this.name = file.name;
            this.file = file;
        },

        /**
         * 上传表格
         */
        fnUplaoFile () {
            if(!this.name) {
                this.$notify({
                    title: '警告',
                    message: '请先上传表格',
                    type: 'warning',
                    duration: 2000
                });
                return;
            }

            let form = new FormData();

            form.append("file", this.file);

            this.$post('/student/stuagent_employee_link%5Cimport', form, resp => {
                event.target.value = null;
                if (resp.code == 1) {
                    if(resp.data.result == 1) {
                        this.getTableData(1);
                        this.dialog.dialogUpload = !this.dialog.dialogUpload;
                        this.$notify({
                            title: '提示',
                            message: '上传成功',
                            type: 'success',
                            duration: 2000
                        });
                        this.file = '';
                        this.name = '';
                    } else {
                        this.tableDataError = resp.data.fail_reason_list;
                        this.dialog.dialogError = !this.dialog.dialogError;
                    }
                } else {
                    this.$notify({
                        title: '警告',
                        message: resp.msg,
                        type: 'warning',
                        duration: 2000
                    });
                }
            });
        },

        /**
         * 数据排序
         */
        handleSortChanged(data) {
            let sortTypeMap = {
                ascending: 0,
                descending: 1
            };

            let sortFieldMap = {
                link_time: 0
            };

            if (data.order) {
                this.filterData.sort_field = sortFieldMap[data.prop];
                this.filterData.sort_type = sortTypeMap[data.order];
            } else {
                this.filterData.sort_field = '';
                this.filterData.sort_type = '';
            }

            this.getTableData();
        },

        /**
         * 全选逻辑操作
         */
        fnSelect(selection) {
            if(selection.length == this.tableData.length) {
                this.checkedAll = true;
            }else{
                this.checkedAll = false;
            }
            if(selection.length > 0 && selection.length < this.tableData.length) {
                this.checkIndeterminate = true;
            }else{
                this.checkIndeterminate = false;
            }
        },
        fnSelectAllTop(selection) {
            if(selection.length > 0) {
                this.checkedAll = true;
            }else{
                this.checkedAll = false;
            }
            if(selection.length > 0 && selection.length < this.tableData.length) {
                this.checkIndeterminate = true;
            }else{
                this.checkIndeterminate = false;
            }
        },
        fnChangeChecked() {
            if(this.checkedAll){
                this.toggleSelection(1);
            }else{
                this.toggleSelection();
            }
        },
        toggleSelection(rows) {
            if (rows) {
                this.$refs.companyStaffSeting.toggleAllSelection();
            } else {
                this.$refs.companyStaffSeting.clearSelection();
            }
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },

        selectable (row,index) {
            if(row.parent_stuagent_employee.status) {
                return true;
            } else {
                return false;
            }
        },

        /**
         * 查看图片
         * @param   {String}    images      //单图预览
         * @param   {Array}     images      //多图预览
         */
        fnShowPreview(images) {
            if(images && Object.prototype.toString.call(images) == '[object String]') {
                this.$refs.preview.show([
                    images
                ]);
            } else if (images && Object.prototype.toString.call(images) == '[object Array]') {
                this.$refs.preview.show(images);
            } else {
                this.$message({
                    type: 'warning',
                    message: '图片类型错误'
                });
            }
        },

        /**
         * 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        }
    }
};
</script>

<style lang="less" scoped>
    .container {
        background-color: #fff;
        display: flex;
        flex-direction: column;
        position: relative;
        width: 100%;
        .tableData {
            width: calc(100% - 48px);
            margin: 0 24px 0 24px;
        }
        .companyStaffSeting-head {
            width: 100%;
            height: 68px;
            display: flex;
            align-items: center;
            box-sizing: border-box;
            padding: 0 35px;
            border-bottom: 1px #f4f4f4 solid;
            margin-bottom: 24px;
            justify-content: space-between;
            &-title {
                color: #333333;
                font-size: 20px;
                font-weight: 500;
                position: relative;
                &::before {
                    content: '';
                    position: absolute;
                    width: 3px;
                    height: 20px;
                    background: #1890FF;
                    top: 0px;
                    margin-left: -10px;
                }
            }
            &-wrap {
                display: flex;
                align-items: center;
                height: 32px;
            }
        }
        .header-nav {
            position: relative;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            justify-content: space-between;
            padding-left: 24px;
            margin-bottom: 14px;
            .header-left, .header-right {
                display: flex;
                align-items: center;
                flex-wrap: wrap;
            }
            .header-new-box {
                display: flex;
                margin-right: 15px;
                align-items: center;
                color: #606266;
                margin-bottom: 10px;
                white-space: nowrap;
                &-title {
                    margin-right: 2px;
                    white-space: nowrap;
                }
            }
        }
        /* 表单 */
        .scope-price {
            width: 50px;
            height: 50px;
        }
        /* 字体高亮 */
        .cursor-font {
            color: rgb(64, 158, 255);
            cursor: pointer;
        }
        /* 分页 */
        .pagination-wrapper {
            padding: 10px 24px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /* 排序 */
    .sort-wrap {
        display: flex;
        align-items: center;
        white-space: nowrap;
        cursor: pointer;
        text-align: left;
        .sort-spliter {
            width: 1px;
            height: 12px;
            background: rgba(235, 235, 235, 1);
            margin: 0 10px;
            }
            .btn-sort {
            font-size: 14px;
            line-height: 1;
            color: #ccc;
            &:hover {
                color: #20a0ff;
            }
        }
    }
    .el-button-left {
        margin-left: 40px;
    }
    .el-button-right {
        margin-right: 10px;
    }
    .staff {
        &-title {
           color: #333333;
           font-size: 14px;
           margin-bottom: 24px;
           display: inline-block;
        }
        .dialog-footer {
            width: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        &-wrap {
            width: 100%;
            display: flex;
            flex-wrap: wrap;
            box-sizing: border-box;
            .staff-wrap-name {
                width: 100%;
                display: flex;
                justify-content: center;
                margin-top: 20px;
                color: #333;
                font-size: 14px;
            }
            .staff-radio {
                width: 125px;
                height: 15px;
                display: flex;
                align-items: center;
                margin-bottom: 24px;
                margin-right: 0px;
            }
            .staff-radio:nth-child(5n) {
                width: 75px;
            }
        }
    }
    .user {
        .user-wrap {
            width:424px;
            height:32px;
            border-radius:4px;
            border:1px dashed rgba(184,184,184,1);
            display: flex;
            justify-content: center;
            align-items: center;
            color: #20A0FF;
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            .el-icon-hand-iconjia {
                font-size: 15px;
                font-weight: bold;
                margin-right: 10px;
                color: #20A0FF;
            }
        }
        .user-info {
            width:424px;
            height:32px;
            background:rgba(255,255,255,1);
            border-radius:4px;
            border:1px solid rgba(0,0,0,0.15);
            display: flex;
            align-items: center;
            padding-left: 12px;
            color: #333333;
            font-size: 14px;
            cursor: pointer;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    }
    .upload {
        width: 100%;
        display: flex;
        justify-content: center;
        position: relative;
        .upload-wrap {
            display: flex;
            justify-content: center;
            align-items: center;
            width:520px;
            height:36px;
            border-radius:4px;
            border:1px dashed rgba(194,194,194,1);
            color: #C2C2C2;
            font-size: 14px;
            cursor: pointer;
            .el-icon-upload2 {
                color: #C2C2C2;
                font-weight: bold;
                margin-right: 10px;
            }
        }
        .upload-wrap-success {
            display: flex;
            justify-content: space-between;
            padding: 0 12px;
            width:520px;
            height:36px;
            border-radius:4px;
            border:1px dashed rgba(194,194,194,1);
            color: #333333;
            font-size: 14px;
            align-items: center;
            cursor: pointer;
            .el-icon-upload2 {
                color: #C2C2C2;
                font-weight: bold;
                margin-right: 10px;
            }
        }
        .import-input {
            position: absolute;
            left: 0;
            top: 0;
            opacity: 0;
            width: 520px;
            height: 36px;
            cursor: pointer;
        }
    }
    .upload-main {
        width: 520px;
        height: 15px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-top: 12px;
        margin-bottom: 30px;
        &-text {
            color: #999999;
            font-size: 14px;
        }
        .upload-down {
            color: #1890FF;
            font-size: 14px;
            cursor: pointer;
        }
    }
    .error {
        &-title {
            color: #333333;
            font-size: 14px;
            margin-bottom: 24px;
        }
    }
    .zd-user-search {
        margin-left: 8px !important;
    }
</style>
<style lang="less">
    .companyStaffSeting{
        .el-table__body-wrapper .el-table__body .el-table__row td {
            border-right: none;
        }
        .el-table__header-wrapper .el-table__header .has-gutter tr th {
            border-right: none;
        }
        .el-table .el-table_1_column_6  .cell {
            position: relative;
        }
        .el-range-editor--small .el-range-separator{
            padding: 0 1px !important;
        }
        .el-dialog__header {
            padding-top: 10px;
            box-shadow:0px 1px 0px 0px rgba(233,233,233,1);
            display: flex;
            align-items: center;
            background: #FAFAFA;
            border-radius: 4px 4px 0 0;
            .el-dialog__title {
                font-weight: 500;
                color: #333;
                font-size: 14px;
            }
            .el-icon-close:before {
                color: rgb(194,194,194);
                font-size: 17px;
                font-weight: bold;
            }
            .el-dialog__headerbtn {
                top: 14px;
            }
        }
        .el-radio-group {
            display: flex;
            flex-wrap: wrap;
        }
        .el-dialog__body {
            padding-bottom: 0px;
        }
        .user-title .el-form-item__label {
            color: #333;
            font-size: 14px;
        }
        .user{
            .el-form-item__label {
                line-height: 32px;
                color: #333;
                margin-top: 4px;
            }
        }
        .el-dialog {
            border-radius: 4px;
        }
        .el-dialog__body {
            padding: 32px;
        }
        .zd-dialogUser .el-dialog__body {
            padding: 32px 60px 0 55px;
        }
    }
</style>
